﻿using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using Common.Constants;
using Common.Helper;

namespace DataAccess
{
    public class DirectorateDataAccess
    {
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static DirectorateDataAccess Instance { get; private set; }
        /// <summary>
        /// Initializes the <see cref="DirectorateDataAccess" /> class.
        /// </summary>
        static DirectorateDataAccess() { Instance = new DirectorateDataAccess(); }

        /// <summary>
        /// Gets the by id.
        /// </summary>
        /// <param name="directorateId">The directorate id.</param>
        /// <returns></returns>
        public IDataReader GetById(Guid directorateId)
        {
            if (directorateId == Guid.Empty)
            {
                return null;
            }
            var colParameter = new Collection<SqlParameter>
               {
                   new SqlParameter("DirectorateID", directorateId)
               };
            var dataReader = SqlHelper.ExecuteReader(ProcedureStores.GetByIdDirectorate, colParameter);
            return dataReader;
        }

        /// <summary>
        /// Gets all.
        /// </summary>
        /// <param name="orgId">The org id.</param>
        /// <param name="include">if set to <c>true</c> [include].</param>
        /// <returns></returns>
        public IDataReader GetAll(Guid orgId,bool include)
        {
            var colParameter = new Collection<SqlParameter>
                                   {
                                       new SqlParameter("OrgID",orgId),
                                       new SqlParameter("Include",include)
                                   };
            var dataReader = SqlHelper.ExecuteReader(ProcedureStores.GetAllDirectorate, colParameter);
            return dataReader;
        }
    }
}
